package com.ithema.controller;

import com.ithema.entity.Category;
import com.ithema.entity.Result;
import com.ithema.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping("/insert")
    public Result insert(@RequestBody @Validated(Category.Insert.class) Category category) {
        categoryService.insert(category);
        return Result.success() ;
    }

    @PostMapping("/list")
    public Result categoryList() {
        return Result.success(categoryService.categoryList());
    }
    @PostMapping("/detail")
    public Result categoryDetail(Integer id) {
        return Result.success(categoryService.categoryDetail(id));
    }

    @PostMapping("/update")
    public Result update(@RequestBody @Validated(Category.Update.class) Category category) {
        categoryService.update(category);
        return Result.success();
    }
    @PostMapping("/delete")
    public Result delete(Integer id) {
        categoryService.delete(id);
        return Result.success();
    }
}
